<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <title>ueditor图片对话框</title>
    <script type="text/javascript" src="../internal.js"></script>

    <!-- jquery -->
    <script type="text/javascript" src="../../third-party/jquery-1.10.2.min.js"></script>
    <script type="text/javascript" src="../../third-party/layer/layer.js"></script>
</head>
<style type="text/css">
		.inputBox {
		      width: 100px;
		      height: 50px;
		      background: green;
		      color: white;
		      font-size: 16px;
		      text-align: center;
		      line-height: 50px;
		      border-radius: 4px;
		      cursor: pointer;
		    }
			.wrapper{
				padding:10px;
				}
			#tips{
				padding:10px 0;
				color:#d80f0f;
				font-size:16px;
			}
	</style>
<body>

<div class="wrapper">
    <input type="file" id="wordFile" name="wordFile" size="15" input enctype="multipart/form-data" maxlength="100" onchange="uploadWord()">
    <div id="tips">点击选择文件按钮，上传后成功后完成内容编辑</div>
    <div id="img_area"></div>
</div>
<script type="text/javascript">

    window.onload = function () {
        initButtons();
    };
    function uploadWord() {
        var file = $("#wordFile").prop('files')[0];
        var data = new FormData();
        data.append('file', file);  //参数名：file
        var protocolStr = document.location.protocol;
        var fileapihost = "https://gateway.instrument.com.cn/common-api/file/word/word2html";
        $.ajax({
            url: fileapihost,
            type: 'POST',
            data: data,
            cache: false, //禁止浏览器对该URL的缓存
            contentType: false,
            processData: false,
            success: function(res){
                var code = res.code;
                if (code === 200) {
                    var html = res.data;
                    $('#img_area').html(html);
					$('#tips').html("预览：")
                } else {
                    layer.msg(res.message);
                }

            }
        });
    }

    /* 初始化onok事件 */
    function initButtons() {
        dialog.onok = function () {
            var html = $('#img_area').html();
            if (html) {
                editor.execCommand('inserthtml', html);
                //editor.execCommand('insertimage', list);
            }
        };
    };
</script>

</body>
</html>
